/* eslint-disable no-alert */
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Switch, Redirect } from 'react-router'
import { PrivateRoute } from 'components/route'
import Fullscreen from 'react-full-screen'
import { Root as RootStyle } from 'style'
import { global as globalDuck, config as configDuck } from 'ducks'
import Label from '../labelView'
import Review from '../reviewView'
import Judge from '../judgeView'
import Test from './test'

class PrivateHomeView extends Component {
  componentDidMount() {
    const { actionCheckReturnUrl } = this.props
    actionCheckReturnUrl()
  }

  render() {
    const { user, fullScreen, setFullScreen } = this.props
    return (
      <RootStyle>
        <Fullscreen enabled={fullScreen} onChange={setFullScreen}>
          <Switch>
            <PrivateRoute exact path="/" component={Test} />
            <PrivateRoute exact={false} path="/label/:pid" component={Label} />
            <PrivateRoute exact={false} path="/review/:pid" component={Review} />
            <PrivateRoute exact={false} path="/judge/:pid" component={Judge} />
            <Redirect exact path="*" to="/error" />
          </Switch>
        </Fullscreen>
      </RootStyle>
    )
  }
}

const mapStateToProps = state => ({
  user: globalDuck.selectors.user(state),
  fullScreen: configDuck.selectors.fullScreen(state),
})

const mapDispatchToProps = {
  actionCheckReturnUrl: globalDuck.creators.actionCheckReturnUrl,
  ...configDuck.creators,
}

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(PrivateHomeView)
